﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Rose.Models;


namespace Rose.Helper
{
   
    public class CheckHelpModel
    {
        private    Database_RoseEntities db = new Database_RoseEntities();

        /// <summary>
        /// 返回的数值只是一个复制，不能作为保存;check的作用只是检查是否参数为空，并且返回一个复制值
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public  RequestFriend CheckRequestFriend(string id)
        {

            Guid guidId = new Guid(id);
            RequestFriend returnModel = db.RequestFriends.Where(c => c.Id == guidId).FirstOrDefault();
            if (returnModel == null)
                throw new ArgumentNullException();
            return returnModel;
            

        }
        public  UserInfo CheckUserInfo(string userId)
        {
            UserInfo returnModel = db.UserInfos.Where(c => c.Id == userId).FirstOrDefault();
            if (returnModel == null)
                throw new ArgumentNullException();
            return returnModel;
        }
        
     
        public  FriendRelation CheckFriendRelation(string id)
        {
           Guid guidId = new Guid(id);
           FriendRelation returnModel = db.FriendRelations.Where(c => c.Id == guidId).FirstOrDefault();
            if (returnModel == null)
                throw new ArgumentNullException();
            return returnModel;
        }

        public  FriendRelation CheckFriendRelation(string selfId, string friendId)
        {
            FriendRelation returnModel = db.FriendRelations.Where(c => c.UserId == selfId && c.FriendId == friendId).FirstOrDefault();
            if (returnModel == null)
                throw new ArgumentNullException();
            return returnModel;
        }

        public  FeedBack CheckFeedBack(string id)
        {
            Guid guidId = new Guid(id);
            FeedBack returnModel = db.FeedBacks.Where(c => c.Id == guidId).FirstOrDefault();
            if (returnModel == null)
                throw new ArgumentNullException();
            return returnModel;
        }

        public  RequestLover CheckRequestLover(string id)
        {
            Guid guidId = new Guid(id);
            RequestLover returnModel = db.RequestLovers.Where(c => c.Id == guidId).FirstOrDefault();
            if (returnModel == null)
                throw new ArgumentNullException();
            return returnModel;
        }

        public  FocusRelation CheckFocusRelation(string id)
        {
            Guid guidId = new Guid(id);
            FocusRelation returnModel = db.FocusRelations.Where(c => c.Id == guidId).FirstOrDefault();
            if (returnModel == null)
                throw new ArgumentNullException();
            return returnModel;
        }

        /// <summary>
        /// id 指的是guidId
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public  LoverRelation CheckLoverRelation(string id)
        {
            Guid guidId = new Guid(id);
            LoverRelation returnModel = db.LoverRelations.Where(c => c.Id == guidId).FirstOrDefault();
            if (returnModel == null)
                throw new ArgumentNullException();
            return returnModel;
        }

        public  LoverRelation CheckLoverRelation(string manId, string womanId)
        {
            LoverRelation returnModel = db.LoverRelations.Where(c=>c.ManId==manId&& c.WomanId==womanId).FirstOrDefault();
            if (returnModel == null)
                throw new ArgumentNullException();
            return returnModel;
        }

       

        public  Album CheckAlbum(string id)
        {
            Guid guidId = new Guid(id);
            Album returnModel = db.Albums.Where(c => c.Id == guidId).FirstOrDefault();
            if (returnModel == null)
                throw new ArgumentNullException();
            return returnModel;
        }

       

        public  Feeling CheckFeeling(string id)
        {
            Guid guidId = new Guid(id);
            Feeling returnModel = db.Feelings.Where(c => c.Id == guidId).FirstOrDefault();
            if (returnModel == null)
                throw new ArgumentNullException();
            return returnModel;
        }

        public  Article CheckArticle(string id)
        {
            Guid guidId = new Guid(id);
            Article returnModel = db.Articles.Where(c => c.Id == guidId).FirstOrDefault();
            if (returnModel == null)
                throw new ArgumentNullException();
            return returnModel;
        }

        public  ArticleComment CheckArticleComment(string id)
        {
            Guid guidId = new Guid(id);
            ArticleComment returnModel = db.ArticleComments.Where(c => c.Id == guidId).FirstOrDefault();
            if (returnModel == null)
                throw new ArgumentNullException();
            return returnModel;
        }

        public  Favorite CheckFavorite(string id)
        {
            Guid guidId = new Guid(id);
            Favorite returnModel = db.Favorites.Where(c => c.Id == guidId).FirstOrDefault();
            if (returnModel == null)
                throw new ArgumentNullException();
            return returnModel;
        }

        public  FeelingComment CheckFeelingComment(string id)
        {
            Guid guidId = new Guid(id);
            FeelingComment returnModel = db.FeelingComments.Where(c => c.Id == guidId).FirstOrDefault();
            if (returnModel == null)
                throw new ArgumentNullException();
            return returnModel;
        }



        public  string CheckCurrentUserId()
        {
            string selfId = HttpContext.Current.User.Identity.Name;
            if (selfId == null)
                throw new ArgumentNullException();
            
            return selfId;
        }
        public  Category CheckCategory(string Id)
        {
            Guid guidId = new Guid(Id);
            Category returnModel = db.Categories.Where(c => c.CategoryId == guidId).FirstOrDefault();
            if (returnModel == null)
                throw new ArgumentNullException();
            return returnModel;
        }
        public  Post CheckPost(string Id)
        {
            Guid guidId = new Guid(Id);
            Post returnModel = db.Posts.Where(c => c.PostId == guidId).FirstOrDefault();
            if (returnModel == null)
                throw new ArgumentNullException();
            return returnModel;
        }

        public  PostComment CheckPostComment(string Id)
        {
            Guid guidId = new Guid(Id);
            PostComment returnModel = db.PostComments.Where(c => c.Id == guidId).FirstOrDefault();
            if (returnModel == null)
                throw new ArgumentNullException();
            return returnModel;
        }

        public  string CheckCity(int cityId)
        {
            var city = db.Cities.Where(c => c.CityId==cityId).FirstOrDefault();
            if (city == null)
                return "未知";
            return city.Name;
        }
        public  string CheckCollege(int collegeId)
        {
            var college = db.Colleges.Where(c => c.CollegeId == collegeId).FirstOrDefault();
            if (college == null)
                return "未知";
            return college.Name;
        }
        public  string CheckMajor(int majorId)
        {
            var major = db.Majors.Where(c => c.MajorId == majorId).FirstOrDefault();
            if (major == null)
                return "未知";
            return major.Name;
        }
    }
}